import java.util.ArrayList;

public class Vertex {

	private String name;
	private ArrayList<Edge> adj = new ArrayList<Edge>();
	private double leastCost;
	private double mostCost;

	public Vertex(String name) {
		this.name = name;
		reset();
	}

	public void reset() {
		leastCost = 0;
		mostCost = -1;
	}

	public String getName() {
		return name;
	}

	public void addEdge(Vertex vertex, double cost) {
		adj.add(new Edge(vertex, cost));
	}

	public boolean hasDestination(Vertex vertex) {
		for (Edge edge : adj) {
			if (edge.getDestination().equals(vertex)) {
				return true;
			}
		}
		return false;
	}

	public void setLeastCost(double cost) {
		if (leastCost <= cost) {
			leastCost = cost;
		}
	}

	public void setMostCost(double cost) {
		if (mostCost == -1 || mostCost >= cost) {
			mostCost = cost;
		}
	}

	public void setEdgesLeastCost() {
		for (Edge edge : adj) {
			edge.setLeastCost(leastCost);
		}
	}

	public void setEdgesMostCost() {
		if (adj.size() == 0) {
			mostCost = leastCost;
		} else {
			for (Edge edge : adj) {
				setMostCost(edge.getDestination().getMostCost()
						- edge.getCost());
			}
		}
	}

	private double getMostCost() {
		return mostCost;
	}

	private double getLeastCost() {
		return leastCost;
	}

	public String toString() {
		return name + "-> leastCost " + getLeastCost() + " | " + name
				+ " -> mostCost " + getMostCost();
	}

}